home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*
- * snurb.c
- */
-
- #include <gl.h>
- #include <device.h>
- #include <math.h>
- #include <stdio.h>
- #include "defines.h"
- #include "snurb.h"
- #include "data.h"
-
- #include "event.h"
- #include "light.h"
- #include "menu.h"
- #include "draw.h"
- #include "rotate.h"
- #include "control.h"
-
-
- /* window information */
- long origin_x, origin_y;
- long size_x, size_y;
- float aspect;
-
- Boolean sb_exists=FALSE;
-
-
- extern Matrix identity_matrix;
-
- void main()
- {
- foreground();
-
-
- /* initialize everything */
- init_window();
- init_events();
- init_data();
- make_lights();
- init_menus();
-
- /* draw it once, then let the events do everything */
- draw_display();
-
- /* event() looks for the events (as in init_events) and passes
- them on to the appropriate routines */
- while(TRUE)
- event();
- }
-
-
- long snurb_window;
-
- /*
- * Opens the window and sets up the graphic mode.
- */
- void init_window(void)
- {
- snurb_window = winopen("Snurbs");
- doublebuffer();
- RGBmode();
- gconfig();
-
- zbuffer(TRUE);
- lsetdepth(0, 0x7fffff);
-
- getorigin(&origin_x, &origin_y);
- getsize(&size_x, &size_y);
- aspect = (float)size_x/(float)size_y;
-
- mmode(MVIEWING);
-
- #ifdef spaceball
- sb_exists = sbInit();
- #endif
- }
-
-
-
- /*
- * Tells event manager what to pay attention to.
- */
- void init_events(void)
- {
- /* ESC key and WINQUIT quit the program */
- add_event(ANY, ESCKEY, UP, quit, NULL);
- qdevice(ESCKEY);
- add_event(ANY, WINQUIT, ANY, quit, NULL);
- qdevice(WINQUIT);
- add_event(ANY, WINSHUT, snurb_window, quit, NULL);
- qdevice(WINSHUT);
-
-
- /* window redraw events */
- add_event(ANY, REDRAW, snurb_window, redraw, 0);
- qdevice(REDRAW);
-
- add_event(snurb_window, LEFTMOUSE, UP, process_left_up, NULL);
- add_event(snurb_window, LEFTMOUSE, DOWN, process_left_down, NULL);
- qdevice(LEFTMOUSE);
-
- add_event(snurb_window, MIDDLEMOUSE, UP, process_middle_up, NULL);
- add_event(snurb_window, MIDDLEMOUSE, DOWN, process_middle_down, NULL);
- qdevice(MIDDLEMOUSE);
-
- add_event(snurb_window, MOUSEX, ANY, process_mouse_motion, NULL);
- add_event(snurb_window, MOUSEY, ANY, process_mouse_motion, NULL);
- }
-
-
-
- /*
- * Called by the event manager whenever a redraw event occurs,
- * e.g. when the window is resized.
- */
- void redraw(void)
- {
- getorigin(&origin_x, &origin_y);
- getsize(&size_x, &size_y);
-
- aspect = (float)size_x/(float)size_y;
-
- viewport(0, size_x-1, 0, size_y-1);
-
- draw_display();
- }
-
-
-
- /*
- * Outta here.
- */
- void quit(void)
- {
- gexit();
- exit(0);
- }
-
-
- /* Set initial perspective and viewing */
- void set_view(int mode)
- {
- if (mode == MVIEWING)
- {
- mmode(MVIEWING);
- perspective(400, aspect, 1.0, 10.0);
-
- loadmatrix(identity_matrix);
- }
- else if (mode == MSINGLE)
- perspective(400, aspect, 1.0, 10.0);
-
- translate(0.0, 0.0, -5.0);
- rotate(450,'x');
- rotate(-450,'y');
- }
-
-